#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
验证当前运行程序的时间间隔
"""

from datetime import datetime

def verify_intervals():
    print("=== 当前运行实例的时间间隔验证 ===")
    print()
    
    # 从最新日志提取的时间戳数据
    current_reports = [
        (1757398231049, "system.cpu.util", "14:10:31"),
        (1757398231491, "system.cpu.num", "14:10:31"),  
        (1757398232826, "vm.memory.size[total]", "14:10:32"),
        (1757398233247, "vm.memory.util", "14:10:33"),
        (1757398233674, "system.hostname", "14:10:33"),
    ]
    
    print("当前运行实例的上报时间戳:")
    for timestamp, item_key, log_time in current_reports:
        dt = datetime.fromtimestamp(timestamp/1000)
        print(f"- {item_key}: {timestamp} ({dt.strftime('%H:%M:%S.%f')[:-3]}, 日志:{log_time})")
    
    # 现在基于这个新的基准，预测下一轮上报
    memory_total_timestamp = 1757398232826
    memory_total_time = datetime.fromtimestamp(memory_total_timestamp/1000)
    
    print(f"\nvm.memory.size[total] 基准时间:")
    print(f"时间戳: {memory_total_timestamp}")
    print(f"时间: {memory_total_time.strftime('%Y-%m-%d %H:%M:%S.%f')[:-3]}")
    
    # 预测下一次上报时间
    print(f"\n基于系统30秒固定间隔，下一轮应该在:")
    next_round = memory_total_timestamp + 30000  # 30秒后
    next_time = datetime.fromtimestamp(next_round/1000)
    print(f"时间戳: {next_round}")
    print(f"时间: {next_time.strftime('%H:%M:%S.%f')[:-3]} (约 14:11:02)")
    
    print(f"\n如果修复生效，vm.memory.size[total] 下次单独上报应该在:")
    next_60s = memory_total_timestamp + 60000  # 60秒后
    next_60s_time = datetime.fromtimestamp(next_60s/1000)
    print(f"时间戳: {next_60s}")
    print(f"时间: {next_60s_time.strftime('%H:%M:%S.%f')[:-3]} (约 14:11:32)")
    
    print("\n=== 问题确认 ===")
    print("从当前日志可以清楚看到:")
    print("1. API配置返回正确: vm.memory.size[total] updateIntervalSeconds=60")
    print("2. 但仍显示'动态监控项调度器未启动，使用硬编码上报作为备用'")  
    print("3. 所有监控项在30秒内连续上报，而不是按各自的间隔")
    print("4. 说明JSON字段映射修复还未生效（程序未重新编译）")
    
    return next_round, next_60s

if __name__ == "__main__":
    verify_intervals()